package www.openteam.com.presenter.business;

import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.DeleteInfo;
import www.openteam.com.contract.business.QryCstChildInfoContract;
import www.openteam.com.model.business.QryCstChildInfoModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.QryCstmChildInfoFragment;

/**
 * Created by OT on 2017-10-10.
 */

public class QryCstChildInfoPresenter extends BasePresenter<QryCstmChildInfoFragment>  implements QryCstChildInfoContract.MPresenter {

    @Override
    public void updateInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price, String eprodno) {
        ((QryCstChildInfoModel) getiModelMap().get("QryChild"))
                .updateCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor
                        , paynumb, othernumb, price, eprodno, new QryCstChildInfoModel.UpdateCustomOrderItemInfoOnListener() {
                            @Override
                            public void updateCOIISuccess(ApprovalStatu updateState) {
                                getIView().updateSucces(updateState);
                            }

                            @Override
                            public void updateCOIIFail(Throwable throwable) {
                                getIView().updateFail(throwable);
                            }
                        });
    }

    @Override
    public void insertInfo(int id, String prodno, String wraptype, String paperinf, String senddate, String technicsinf, String printcolor, String paynumb, String othernumb, String price) {
        ((QryCstChildInfoModel) getiModelMap().get("QryChild"))
                .insertCustomOrderItemInfo(id, prodno, wraptype, paperinf, senddate, technicsinf, printcolor,
                        paynumb, othernumb, price, new QryCstChildInfoModel.
                                InsertCustomOrderItemInfoOnListener() {
                            @Override
                            public void insertCOIISuccess(ApprovalStatu approvalStatu) {
                                getIView().insertSucces(approvalStatu);
                            }

                            @Override
                            public void insertCOIIFail(Throwable throwable) {
                                getIView().insertFail(throwable);
                            }
                        });
    }

    @Override
    public void deleteInfo(int zbid, String prodno) {
        ((QryCstChildInfoModel) getiModelMap().get("QryChild"))
                .deleteCustomOrderItemInfo(zbid, prodno, new QryCstChildInfoModel.EditCustomOrderItemInfoOnListener() {
                    @Override
                    public void deleteECOIISuccess(DeleteInfo deleteInfo) {
                        getIView().deletSucces(deleteInfo);
                    }

                    @Override
                    public void deleteECOIIFail(Throwable throwable) {
                        getIView().deletFail(throwable);
                    }
                });
    }

    @Override
    public HashMap<String, IModel> getiModelMap() {

        return loadModelMap(new QryCstChildInfoModel());
    }
    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("QryChild", models[0]);
        return hashMap;
    }


}
